package reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

/**
 * 通过反射机制获取Method对应的方法信息
 */
public class ReflectDemo6 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Person");
        Method method = cls.getMethod("say", String.class,int.class);

        String name = method.getName();
        System.out.println("方法的名字:"+name);

        Class returnType = method.getReturnType();
        System.out.println("返回值类型:"+returnType.getName());

        int count = method.getParameterCount();
        System.out.println("参数个数:"+count);

        Class[] paramTypes = method.getParameterTypes();
        for (Class paramType : paramTypes) {
            System.out.println("参数类型:"+paramType.getName());
        }

        int modifiers = method.getModifiers();
        switch (modifiers){
            case Modifier.PUBLIC:
                System.out.println("访问权限为public");
                break;
            case Modifier.PRIVATE:
                System.out.println("访问权限为private");
                break;
            case Modifier.PROTECTED:
                System.out.println("访问权限为protected");
                break;
            default:
                System.out.println("访问权限为default");
        }
    }
}
